package com.slg.android.manyanime.tasks;

import android.os.AsyncTask;

import com.slg.android.manyanime.utils.HttpTool;

import org.json.JSONException;
import org.json.JSONObject;

import java.io.UnsupportedEncodingException;

/**
 * Created by Darker on 2015/3/11.
 */
public class CoserListTask extends AsyncTask<String,Integer,JSONObject> {

    private TaskProcessor processor;
    public CoserListTask (TaskProcessor processor) {
        this.processor = processor;
    }
    @Override
    protected JSONObject doInBackground(String... params) {
        JSONObject ret = null;
        String coserUrl = params[0];

        byte[] bytes = HttpTool.get(coserUrl);
        if (bytes != null) {
            try {
                String str = new String(bytes, "utf-8");
                ret = new JSONObject(str);
            } catch (UnsupportedEncodingException e) {
                e.printStackTrace();
            } catch (JSONException e) {
                e.printStackTrace();
            }
        }
        return ret;
    }

    @Override
    protected void onPostExecute(JSONObject jsonObject) {
        if(processor != null){
            processor.processResult(jsonObject);
        }
    }
}
